<!--
 * @Author: mhb
 * @Date: 2021-12-21 17:38:02
 * @LastEditTime: 2022-01-12 10:26:16
 * @LastEditors: Please set LastEditors
 * @Description: 资料扣分
 * @FilePath: \cscec-pms-admin-3\src\views\quality\resultsManagement\QCActivityResult\DataDeduction.vue
-->
<template>
  <div>
    <div class="mb20">
      <title-name title="活动成果"></title-name>
      <a-table ref="table" rowKey="id" :dataSource="form.achievements || []" :pagination="false" :columns="columns">
        <!-- 扣分 -->
        <BaseInputNumber
          v-if="record.status === '评审中' || record.status === '评审完成'"
          slot="deductPointsInput"
          slot-scope="text, record"
          v-model="record.deductPoints"
          placeholder="请输入扣分"
          :min="0"
        />
        <!-- 操作：移除 -->
        <a
          slot="actions"
          slot-scope="text, record"
          @click="
            chooseRow = record
            $refs.viewResultData.visible = true
          "
          >查看</a
        >
      </a-table>
    </div>
    <div>
      <title-name title="评审成员"></title-name>
      <a-table rowKey="userId" :dataSource="form.employees || []" :columns="columns2" :pagination="false"></a-table>
    </div>
    <!-- 成果评审详情信息弹窗 -->
    <ViewResultData ref="viewResultData" :form="chooseRow" />
  </div>
</template>

<script>
import ViewResultData from '../components/ViewResultData' // 表单弹窗

export default {
  name: 'DataDeduction',
  components: {
    ViewResultData
  },
  props: {
    // 表单
    form: {
      type: Object,
      default: () => {}
    },
    // 请求api
    api: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      chooseRow: {}, //选中活动成果
      columns: [
        {
          dataIndex: 'projectName',
          title: '项目名称'
        },
        {
          dataIndex: 'topicName',
          title: '课题名称'
        },
        {
          dataIndex: 'topicTypeName',
          title: '课题类型'
        },
        {
          dataIndex: 'topicRegisterNumber',
          title: '课题注册号'
        },
        {
          dataIndex: 'completeEmployeeNames',
          title: '课题实际完成人'
        },
        {
          dataIndex: 'average',
          title: '资料平均分'
        },
        {
          dataIndex: 'deductPoints',
          title: '资料逾期扣分'
        },
        {
          dataIndex: 'score',
          title: '资料得分',
          customRender(e){
            return e > 0 ? e : 0
          }
        },
        {
          dataIndex: 'sort',
          title: '排名'
        },
        {
          dataIndex: 'status',
          title: '状态'
        },
        {
          dataIndex: 'deductPointsInput ',
          title: '扣分',
          width: 200,
          scopedSlots: { customRender: 'deductPointsInput' }
        },
        {
          dataIndex: 'actions',
          title: '操作',
          width: 80,
          scopedSlots: { customRender: 'actions' }
        }
      ], // 成果表头
      columns2: [
        {
          title: '姓名',
          ellipsis: true,
          dataIndex: 'name'
        },
        {
          title: '职称',
          ellipsis: true,
          dataIndex: 'jobTitle',
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '岗位',
          dataIndex: 'postPNames',
          ellipsis:true,
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '学历',
          ellipsis: true,
          dataIndex: 'specialitieMax',
          customRender(e) {
            return e || '无'
          }
        }
      ] // 人员表头
    }
  },
  methods: {
    /**
     * 提交表单
     */
    handleSubmit() {
      let that = this
      // 校验
      if (!that.form.achievements?.length) {
        that.$message.warning('活动成果列表不能为空！')
      } else {
        let details = that.form.achievements
          ?.filter((i) => !!i.deductPoints && (i.status === '评审中' || i.status === '评审完成'))
          ?.map((i) => ({ reviewAchievementId: i.id, deductPoints: i.deductPoints })) // 扣分项列表
        // 校验是否存在扣分项
        if (!details?.length) {
          that.$message.warning('请至少填写一个扣分项！')
          return
        }
        let form = {
          details,
          id: that.form.id
        } // 表单
        that.$confirm({
          title: '温馨提示',
          content: '确定提交，提交后不可撤回？',
          onOk: () => {
            // 提交表单
            return this.api.deductPoints(form).then((res) => {
              if (res.code === 200 || res.data.code === 200) {
                that.$message.success('提交成功！')
                that.$multiTab.close()
              }
            })
          }
        })
      }
    }
  }
}
</script>
